package com.icedata.sika.core

import com.icedata.sika.bridge.SikaEvent
import com.icedata.sika.util.readAsync
import okhttp3.internal.notifyAll

/**
 * 解析器链
 */
class ParseProcessorBus(sika: Sika) :
    AsyncProcessorBus<ParseProcessor, SikaEvent, List<Command>>(sika) {

    override suspend fun broadcast(data: SikaEvent) {
        lock.readAsync(suspend {
            for (p in processors) {
                p.execute(data, sika).forEach {
                    sika.commandChannel.send(it)
                }
            }
            synchronized(lock) {
                lock.notifyAll()
            }
        })
    }
}